/*
    PhotoFlip, a free 3d photo managment suite.
    Copyright (C) 2007  Elisée MAURER, Gaétan WALTER
    
    This file is part of PhotoFlip.
    Contact: http://www.photoflip.org/

    PhotoFlip is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    PhotoFlip is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PhotoFlip.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "md5.hpp"

#include "md5/md5.h"

std::string str2md5(const char *str) {
	std::string md5string;
	
	md5_state_t state;
	md5_byte_t digest[16];
	 
	md5_init(&state);
	md5_append(&state, (const md5_byte_t *)str, (int)strlen(str));
	md5_finish(&state, digest);
	 
	for(int i = 0; i < 16; i++){
		char tmp[3];
		sprintf(tmp, "%02x", digest[i]);
		tmp[3] = '\0';
		md5string += tmp;
	}
	
	return md5string;

/*
#ifdef WIN32
	md5string = "woops";
#else
	gcry_md_hash_buffer(GCRY_MD_MD5, md5, str, strlen(str));
	{
		char tmp[3];
		for(int k = 0; k < 16; k++) {
			sprintf(tmp, "%02x", md5[k]);
			tmp[3] = '\0';
			md5string += tmp;
		}
	}
#endif
	
	return md5string;*/
}
